<%
	// TODO: move away from JSP ...
	// GET DASSOURCES
	System.out.print("findAction:" + findAction);
if ( findAction == null ) {
	findAction = "list";
}
	String paramstring = "";

	List<DasSource> s = null;

	//default :    
	if ((findAction == null) || (findAction.equals("list"))) {

		s = registry.listServices();

	} else if (findAction.equals("keyword")) {

		s = registry.keywordSearch(keyword);

	} else if (findAction.equals("keywordForTypes")) {

		s = registry.typesSearch(keywordForTypes);

	} else if (findAction.equals("showmine")) {

		
		s = registry.getServicesForEmail(email);
		

	} else if (capabilities.length > 0) {
System.out.println("capablities length is >0");
		String[] coordsys_types = register.getCSTypes();
		String organism = register.getOrganism();
		String[] organisms = new String[1];
		organisms[0] = organism;
		String cs_name = register.getCSName();
		String[] cs_names = new String[1];
		cs_names[0] = cs_name;
		String[] findlabels = register.getLabels();
		String spec=register.getSpec();

		if (findlabels.length == 0)
			findlabels = new String[] { "any" };

		if ((coordsys_types == null) || (capabilities == null)
		|| (findlabels == null)) {
			out.print("unable to contact registry - webservice! please contact webmaster@sanger.ac.uk ");
		} else {

			if (coordsys_types.length < 1) {
		coordsys_types = new String[] { "any" };
			}

			paramstring = "&organism=" + organism + "&cs_name="
			+ cs_name + "&CSTypes=" + coordsys_types[0]
			+ "&capabilities=" + capabilities[0] + "&labels="
			+ findlabels[0]+"&spec="+spec;

			if (capabilities.length > 0) {
		s = registry
				.findService(capabilities[0], coordsys_types,
				cs_names, organisms, findlabels, spec);
			} else {
		s = registry.findService("%", coordsys_types,
				cs_names, organisms, findlabels, spec);
			}
		}
	}

	if ((keyword != null) && (!keyword.equals(""))) {
		paramstring += "&cmd=keyword&keyword=" + keyword;
	} else {
		paramstring += "&cmd="+findAction;
	}
	if ((keywordForTypes != null) && (!keywordForTypes.equals(""))) {
		paramstring += "&cmd=keywordForTypes&keywordForTypes=" + keywordForTypes;
	} else {
		paramstring += "&cmd="+findAction;
	}

	// SORTING

	String sortstring = "";
	String reversestring = "";
	String notreversestring = "";
	if (sort != null) {
		sortstring = "&sort=" + sort;
		//sort das sources!
		if (reverse != null) {
			out.println("<br>sorted reverse by " + sort + "</br>");
			notreversestring += "&reverse=true";

		} else {
			out.println("<br>sorted by " + sort + "</br>");
			reversestring += "&reverse=true";
		}

		out.println("sorted , reverse:" + reverse);

		Comparator dsc = DasSourceComparator.fromString(sort);
		java.util.Collections.sort(s, dsc);
		if (reverse != null) {
			// reverse order
			//java.util.List slist = java.util.Arrays.asList(s);
			out.println("reverse not null:" + reverse);
			java.util.Collections.reverse(s);
			
		}
	}
%>

<%
	// check for the scrolling parameters.

	String posS = request.getParameter("pos");
	int pos = 0;
	try {
		pos = Integer.parseInt(posS);
	} catch (Exception e) {
	}

	int stepsize = DEFAULT_STEPSIZE;

	String stepS = request.getParameter("stepsize");
	try {
		stepsize = Integer.parseInt(stepS);
	} catch (Exception e) {
	}

	int nrServers = s.size();

	if (stepsize < 1)
		stepsize = 1;

	if (stepsize > nrServers)
		stepsize = nrServers;

	if (pos < 0) {
		pos = 0;
	}

	if (pos > nrServers)
		pos = nrServers - stepsize;
%>
